package chapter16;

import chapter16.tankwar.myTank;

import javax.swing.*;
import java.awt.*;

/**
 * @Auther: Tx
 * @Date: 2022/5/28 18:14
 */
public class DrawTank extends JFrame {
    private MyPanel myPanel = null;

    public static void main(String[] args) {
        new DrawTank();

    }

    public DrawTank() {
        myPanel = new MyPanel();
//         添加到窗口
        this.add(myPanel);
//         新建窗口
        this.setSize(1000, 750);
//        设置关闭
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        显示
        this.setVisible(true);

    }
}

class MyPanel extends JPanel {
    chapter16.tankwar.myTank myTank = null;
    public MyPanel(){
        myTank = new myTank(100,100);
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        drawTank(myTank.getX(),myTank.getY(),g,0,0);
    }

    public void drawTank(int x, int y, Graphics g, int direct, int type) {
        switch (type) {
            case 0:
                g.setColor(Color.cyan);
                break;
            case 1:
                g.setColor(Color.yellow);
                break;
        }
        //根据坦克方向，来绘制坦克
        switch (direct) {
            case 0:
                g.fill3DRect(x, y, 10, 60, false);//画左边的轮子
                g.fill3DRect(x + 30, y, 10, 60, false);//画左边的轮子
                g.fill3DRect(x + 10, y + 15, 20, 30, false);
                g.fillOval(x + 10, y + 20, 20, 20);//坦克的盖子
                g.drawLine(x + 20,y+30 ,x+20, y);//坦克的炮筒
                break;

        }
    }
}